package joney.main.views;

import joney.bonjour.BonjourServer;
import joney.main.utils.ProgressMonitor;

import org.eclipse.jface.dialogs.ProgressIndicator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.ISizeProvider;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;


public class DeviceSyncView extends ViewPart{

	public static final String ID= "joney.devicesyncview";

	private BonjourServer server;
	
	public void createPartControl(Composite parent) {
	
		GridLayout layout = new GridLayout();
		layout.numColumns= 1;
		parent.setLayout(layout);
		
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
		
		Label proText = new Label(parent, SWT.None);
		proText.setLayoutData(gd);
		
		ProgressIndicator progressBar = new ProgressIndicator( parent );
		progressBar.setLayoutData(gd);
		
		server = new BonjourServer(new ProgressMonitor( progressBar, proText , true));
		
//		Button sync = new Button(parent, SWT.PUSH);
//		sync.setText("Sync");
//		sync.addSelectionListener(new SelectionAdapter()
//		{
//			public void widgetSelected(SelectionEvent e) {
//				if(server != null)
//				
//			}
//			
//		});
		
		
		server.startRegisterService();
	}
	
	public void dispose()
	{
		System.out.println("Stopping server");
		if(server!= null)
			server.stopRegisterService();
		
		super.dispose();
	}

	public void setFocus() {
		
	}

	
}
